/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package lotteryauto.panel;

import Main.ConfigSelectMain;
import Main.StartMain;
import RTPower.RTFile;
import java.awt.Color;
import java.io.File;
import javax.swing.JOptionPane;

/**
 * 单独一个配置文件显示面板
 *
 * @author jerry
 */
public class SelectConfigListOne extends javax.swing.JPanel {

    /**
     * Creates new form ConfigListOne
     */
    public SelectConfigListOne() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        config_name = new javax.swing.JLabel();
        button_del = new javax.swing.JButton();
        web_tag = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        format_money = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        now_money = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        heart_jump = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        buy_double = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        win_money = new javax.swing.JLabel();
        rule_tag = new javax.swing.JLabel();
        td1 = new javax.swing.JButton();
        td2 = new javax.swing.JButton();
        td3 = new javax.swing.JButton();
        td4 = new javax.swing.JButton();
        td5 = new javax.swing.JButton();
        info_status = new javax.swing.JLabel();
        now_qihao = new javax.swing.JLabel();
        now_msg = new javax.swing.JLabel();
        auto_start = new javax.swing.JButton();

        setBackground(new java.awt.Color(223, 223, 223));
        setAlignmentX(0.0F);
        setAlignmentY(0.0F);
        addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseMoved(java.awt.event.MouseEvent evt) {
                formMouseMoved(evt);
            }
        });

        config_name.setFont(new java.awt.Font("Lucida Grande", 1, 14)); // NOI18N
        config_name.setForeground(new java.awt.Color(102, 102, 102));
        config_name.setText("--");
        config_name.setToolTipText("点击加载此配置文件,并开始运行");
        config_name.setAlignmentY(0.0F);
        config_name.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                config_nameMouseClicked(evt);
            }
        });

        button_del.setForeground(new java.awt.Color(255, 255, 255));
        button_del.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/button_black.png"))); // NOI18N
        button_del.setText("删除");
        button_del.setBorder(null);
        button_del.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        button_del.setMargin(new java.awt.Insets(0, 0, 0, 0));
        button_del.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                button_delActionPerformed(evt);
            }
        });

        web_tag.setText("--");

        jLabel1.setText("初始:");

        format_money.setForeground(new java.awt.Color(77, 0, 69));
        format_money.setText("0");

        jLabel2.setText("当前:");

        now_money.setForeground(new java.awt.Color(153, 0, 51));
        now_money.setText("0");

        jLabel4.setText("心跳:");

        heart_jump.setText("--");

        jLabel6.setText("倍数:");

        buy_double.setForeground(new java.awt.Color(0, 153, 0));
        buy_double.setText("0");

        jLabel8.setText("盈利:");

        win_money.setForeground(new java.awt.Color(0, 124, 0));
        win_money.setText("0");

        rule_tag.setFont(new java.awt.Font("Lucida Grande", 1, 13)); // NOI18N
        rule_tag.setText("规则:");

        td1.setBackground(new Color(233,233,233,0));
        td1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/close.png"))); // NOI18N
        td1.setText("--");
        td1.setActionCommand("1");
        td1.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        td1.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        td1.setSelected(true);
        td1.setSelectedIcon(new javax.swing.ImageIcon(getClass().getResource("/images/open.png"))); // NOI18N

        td2.setBackground(new Color(233,233,233,0));
        td2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/close.png"))); // NOI18N
        td2.setText("--");
        td2.setActionCommand("2");
        td2.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        td2.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        td2.setSelected(true);
        td2.setSelectedIcon(new javax.swing.ImageIcon(getClass().getResource("/images/open.png"))); // NOI18N

        td3.setBackground(new Color(233,233,233,0));
        td3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/close.png"))); // NOI18N
        td3.setText("--");
        td3.setActionCommand("3");
        td3.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        td3.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        td3.setSelected(true);
        td3.setSelectedIcon(new javax.swing.ImageIcon(getClass().getResource("/images/open.png"))); // NOI18N

        td4.setBackground(new Color(233,233,233,0));
        td4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/close.png"))); // NOI18N
        td4.setText("--");
        td4.setActionCommand("4");
        td4.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        td4.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        td4.setSelected(true);
        td4.setSelectedIcon(new javax.swing.ImageIcon(getClass().getResource("/images/open.png"))); // NOI18N

        td5.setBackground(new Color(233,233,233,0));
        td5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/close.png"))); // NOI18N
        td5.setText("--");
        td5.setActionCommand("5");
        td5.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        td5.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        td5.setSelected(true);
        td5.setSelectedIcon(new javax.swing.ImageIcon(getClass().getResource("/images/open.png"))); // NOI18N

        info_status.setForeground(new java.awt.Color(6, 108, 190));
        info_status.setText("--");

        now_qihao.setText("--");

        now_msg.setForeground(new java.awt.Color(153, 153, 153));
        now_msg.setMaximumSize(new java.awt.Dimension(504, 16));
        now_msg.setPreferredSize(new java.awt.Dimension(504, 16));

        auto_start.setForeground(new java.awt.Color(255, 255, 255));
        auto_start.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/button_black.png"))); // NOI18N
        auto_start.setText("下注");
        auto_start.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        auto_start.setMargin(new java.awt.Insets(0, 0, 0, 0));
        auto_start.setSelectedIcon(new javax.swing.ImageIcon(getClass().getResource("/images/button_red.png"))); // NOI18N
        auto_start.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                auto_startActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(292, 292, 292)
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(format_money, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(now_money, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(0, 0, 0)
                                .addComponent(jLabel8)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(win_money, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel4)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(heart_jump, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel6)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(buy_double, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(rule_tag))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(td1, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(td2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(td3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(td4)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(td5)))
                        .addGap(22, 22, 22))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(config_name, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(web_tag, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(button_del, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(auto_start, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(12, 12, 12)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(info_status, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 626, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(now_qihao, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(now_msg, javax.swing.GroupLayout.PREFERRED_SIZE, 504, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {format_money, now_money, win_money});

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {td1, td2, td3, td4, td5});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(4, 4, 4)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel1)
                                .addComponent(format_money)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(td1)
                                .addComponent(td3)
                                .addComponent(td2)
                                .addComponent(td5)
                                .addComponent(td4))
                            .addComponent(info_status))
                        .addGap(5, 5, 5)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(now_qihao, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(now_msg, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                                .addComponent(web_tag, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(config_name, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(button_del, javax.swing.GroupLayout.Alignment.CENTER, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4)
                            .addComponent(heart_jump)
                            .addComponent(now_money)
                            .addComponent(jLabel6)
                            .addComponent(buy_double)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel8)
                                .addComponent(win_money))
                            .addComponent(rule_tag))
                        .addGap(0, 0, 0)
                        .addComponent(auto_start, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(11, Short.MAX_VALUE))
        );

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {td1, td2, td3, td4, td5});

        getAccessibleContext().setAccessibleParent(this);
    }// </editor-fold>//GEN-END:initComponents

    private void formMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseMoved


    }//GEN-LAST:event_formMouseMoved

    /**
     * 删除按钮激活事件
     *
     * @param evt
     */
    private void button_delActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_button_delActionPerformed
        //读取用户名
        String del_name = config_name.getText();
        String web_tagstring = this.web_tag.getText();
        int n = JOptionPane.showConfirmDialog(null, "确认删除此 [ " + del_name + " ] 配置文件?", "确认删除?", JOptionPane.YES_NO_OPTION);
        if (n == JOptionPane.YES_OPTION) {
            String file_path = "." + RTFile.FG + "config" + RTFile.FG + del_name + "_" + web_tagstring + ".txt";

            File file = new File(file_path);
            if (!file.exists()) {
                JOptionPane.showMessageDialog(null, "文件 [ " + file_path + " ] 不存在!");
                return;
            }
            boolean del_status = file.delete();
            if (del_status) {
                //删除文件成功,开始删除面板
                String panel_id = button_del.getActionCommand();
                SelectPanelManage.Delpanel(del_name + "_" + web_tagstring);
                JOptionPane.showMessageDialog(null, "删除配置文件 [ " + del_name + " ] 成功!");

                this.repaint();

            } else {
                JOptionPane.showMessageDialog(null, "删除配置文件 [ " + file_path + " ] 失败!!");
            }
        }
    }//GEN-LAST:event_button_delActionPerformed

    /**
     * 点击用户名激活事件
     *
     * @param evt
     */
    private void config_nameMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_config_nameMouseClicked
        String user_name = config_name.getText();
        String web_tagstring = this.web_tag.getText();
        SelectPanelManage.GoStartMain(user_name + "_" + web_tagstring);
    }//GEN-LAST:event_config_nameMouseClicked

    /**
     * 点击了下注/暂停按钮后的事件
     *
     * @param evt
     */
    private void auto_startActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_auto_startActionPerformed
        //读取用户名
        String del_name = config_name.getText();
        String web_tagstring = this.web_tag.getText();

        boolean buy_status = !(auto_start.isSelected());
        if (!ConfigSelectMain.AllMains.containsKey(del_name + "_" + web_tagstring)) {
            JOptionPane.showMessageDialog(null, del_name + "_" + web_tagstring + " 账号还没有启动!");
            return;
        }
        StartMain Smain = (StartMain) ConfigSelectMain.AllMains.get(del_name + "_" + web_tagstring);
        if (buy_status) {
            Smain.conf_auto_start.setSelected(true);
        } else {
            Smain.conf_auto_stop.setSelected(true);
        }

    }//GEN-LAST:event_auto_startActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    public javax.swing.JButton auto_start;
    public javax.swing.JButton button_del;
    public javax.swing.JLabel buy_double;
    public javax.swing.JLabel config_name;
    public javax.swing.JLabel format_money;
    public javax.swing.JLabel heart_jump;
    public javax.swing.JLabel info_status;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel8;
    public javax.swing.JLabel now_money;
    public javax.swing.JLabel now_msg;
    public javax.swing.JLabel now_qihao;
    public javax.swing.JLabel rule_tag;
    public javax.swing.JButton td1;
    public javax.swing.JButton td2;
    public javax.swing.JButton td3;
    public javax.swing.JButton td4;
    public javax.swing.JButton td5;
    public javax.swing.JLabel web_tag;
    public javax.swing.JLabel win_money;
    // End of variables declaration//GEN-END:variables
}
